<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title></title>
	<link rel="stylesheet" href="/static/layui/css/layui.css">
	<script src="/static/layui/layui.js"></script>
</head>
<body>
	<form class="layui-form" action="{:url('index/guanggaotu_add')}" method="post">
  <div class="layui-form-item">
    <label class="layui-form-label">广告图名称</label>
    <div class="layui-input-inline">
      <input type="text" name="name" required  lay-verify="required" placeholder="请输入广告图名称" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">联动选择框</label>
    <div class="layui-input-inline">
      <select name="sheng" lay-filter="sheng">
        <option value="">请选择省</option>
        {foreach $list as $key=>$vo}
        <option value="{$vo.name}" >{$vo.name}</option>
        {/foreach}
      </select>
    </div>
    <div class="layui-input-inline">
      <select name="shi" id="shi" lay-filter="shi">
        <option value="">请选择市</option>
        <option value=""></option>
      </select>
    </div>
    <div class="layui-input-inline">
      <select name="qu" id="qu">
        <option value="">请选择县/区</option>
        <option value=""></option>
      </select>
    </div>
  </div>
  <div class="layui-upload">
  <button type="button" class="layui-btn" id="test1">广告图</button>
  <div class="layui-upload-list">
    <img class="layui-upload-img" id="demo1" width="100px" height="100px">
    <input type="hidden" id="img" name="img">
    <p id="demoText"></p>
  </div>
  <div style="width: 95px;">
    <div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="demo">
      <div class="layui-progress-bar" lay-percent=""></div>
    </div>
  </div>
</div>   
   <div class="layui-form-item">
    <label class="layui-form-label">添加时间</label>
    <div class="layui-input-inline">
      <input type="date" name="addtime" required  lay-verify="required" placeholder="请输入时间" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">状态</label>
    <div class="layui-input-block">
      <input type="radio" name="status" value="正常" title="正常">
      <input type="radio" name="status" value="禁止" title="禁止" checked>
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <input type="hidden" name="guanggao_id" value="{$id}">
      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
<script src="//res.layui.com/layui/dist/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>
layui.use(['upload', 'element', 'layer','form'], function(){
  var $ = layui.jquery
  ,upload = layui.upload
  ,element = layui.element
  ,layer = layui.layer
  ,form = layui.form;
  form.on('select(sheng)',function(data){
  	var data=data.value;
  	console.log(data);
  	$.ajax({
        url:"{:url('index/diqu')}",
        data:{
        	name:data
        },
        success:function(res){
           var data=res.data;
           data.forEach(function(v){
           	 var sheng='<option value="'+v['name']+'">'+v['name']+'</option>';
             $('#shi').append(sheng);
             form.render();
           })
        }
  	});
  });
  form.on('select(shi)',function(data){
  	var data=data.value;
  	console.log(data);
  	$.ajax({
        url:"{:url('index/diqu')}",
        data:{
        	name:data
        },
        success:function(res){
           var data=res.data;
           data.forEach(function(v){
           	 var sheng='<option value="'+v['name']+'">'+v['name']+'</option>';
             $('#qu').append(sheng);
             form.render();
           })
        }
  	});
  });
  //常规使用 - 普通图片上传
  var uploadInst = upload.render({
    elem: '#test1'
    ,url: '{:url('index/upload')}' //改成您自己的上传接口
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){
        $('#demo1').attr('src', result); //图片链接（base64）
      });
      
      element.progress('demo', '0%'); //进度条复位
      layer.msg('上传中', {icon: 16, time: 0});
    }
    ,done: function(res){
      //如果上传失败
      if(res.code > 0){
        return layer.msg('上传失败');
      }
       if(res.code == 0){
       	$('#img').val(res.data);
        return layer.msg('上传成功');
      }
      //上传成功的一些操作
      //……
      $('#demoText').html(''); //置空上传失败的状态
    }
    ,error: function(){
      //演示失败状态，并实现重传
      var demoText = $('#demoText');
      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
      demoText.find('.demo-reload').on('click', function(){
        uploadInst.upload();
      });
    }
    //进度条
    ,progress: function(n, index, e){
      element.progress('demo', n + '%'); //可配合 layui 进度条元素使用
      if(n == 100){
        layer.msg('上传完毕', {icon: 1});
      }
    }
  });
  
});
</script>
</body>
</html>